import {defineStore} from 'pinia'

export const useCounterStore = defineStore('counter', {
  state: () => ({
    count: 0,
    user: null
  }),
  getters: {
    doubleCount: (state) => state.count * 2,
    isAuthenticated: (state) => !!state.user
  },
  actions: {
    increment() {
      this.count++
    },
    async login(credentials) {
      console.log('this',this,this.user)
      // 模拟异步操作
      // const response = await api.login(credentials)
      this.user = {name:"2222李",age:23}
    },
    logout() {
      this.user = null
    }
  }
})
